package com.yulongtian.interviewWorks.day20221117;

/**
 * https://leetcode.cn/problems/kLl5u1/submissions/
 * 可
 * @author yulongTian
 * @create 2022-11-20 17:15
 */
public class Test03 {
    public static void main(String[] args) {
        int[] numbers = {1, 2, 4, 6, 10};
        int target = 8;

        int[] ints = twoSum(numbers, target);
        System.out.println(ints[0] + "," + ints[1]);
    }

    public static int[] twoSum(int[] numbers, int target) {
        int[] res = new int[2];
        int left = 0;
        int right = numbers.length - 1;

        while (left < right) {
            if (numbers[left] + numbers[right] == target) {
                res[0] = left;
                res[1] = right;
                break;
            }

            if (numbers[left] + numbers[right] > target) {
                right--;
                continue;
            }

            if (numbers[left] + numbers[right] < target) {
                left++;
            }
        }
        return res;
    }

}
